package com.ag.hmk.service.impl;

import java.util.List;

import com.ag.bean.TbUnit;
import com.ag.common.IDUtil;
import com.ag.hmk.dao.HmkUnitDAO;
import com.ag.hmk.service.UnitService;
/**
 * 
 * @author 黄木看
 * 物品单位服务接口实现
 *
 */
public class UnitServImpl implements UnitService {

	private HmkUnitDAO hmkUnitDAO;
	
	/*
	 *删除记录(by id) 
	 */
	public void delete(String unitID) {
		if (unitID!=null) {
			TbUnit tbUnit = hmkUnitDAO.findById(unitID);
			if (tbUnit!=null) {
				tbUnit.setA(IDUtil.DELETE);
				hmkUnitDAO.attachDirty(tbUnit);
			}
		}
	}

	/*
	 * 查询所有记录
	 */
	public List<TbUnit> findAll() {
		return hmkUnitDAO.findByA(IDUtil.PRESERVE);
	}

	/*
	 * 查询一条记录（by id）
	 */
	public TbUnit findByID(String unitID) {
		if (unitID!=null) {
			return hmkUnitDAO.findById(unitID);
		} else {
			return null;
		}
		
	}

	/*
	 * 新增或更新记录
	 */
	public void save(TbUnit unit) {
		if (unit!=null) {
			unit.setA(IDUtil.PRESERVE);
			hmkUnitDAO.attachDirty(unit);
		}
		
	}

	public void setHmkUnitDAO(HmkUnitDAO hmkUnitDAO) {
		this.hmkUnitDAO = hmkUnitDAO;
	}

}
